package edu.spbsu.nonsm00th.computgeom.sort.impl;

import edu.spbsu.nonsm00th.algorithms.sort.Comparator;
import edu.spbsu.nonsm00th.model.Point;
import edu.spbsu.nonsm00th.model.enums.Ratio;
import edu.spbsu.nonsm00th.util.Precondition;

/**
 * Cartesian comparator realization. Cartesian coordinates lexicographic
 * comparator.
 *
 * @author mbuzdov
 */
public class ComparatorDNCartesian implements Comparator<Point> {

    public Ratio compare(final Point a, final Point b) {
        Precondition.argsNotNull(a, b);//TODO: remove preconditions
        Precondition.check(
                a.getDimension() == b.getDimension(),
                "Can not compare objects with different demensions.");

        for (int i = 0; i < a.getDimension(); i++) {
            if (a.getXi(i) > b.getXi(i)) {
                return Ratio.GREATER;
            }
            if (a.getXi(i) < b.getXi(i)) {
                return Ratio.LESS;
            }
        }
        return Ratio.EQUAL;
    }

}
